#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int id[15][15], num;
char a[15][15];
struct Node {
  int id;
  string word;
};
vector<Node> across;
vector<Node> down;
bool solve() {
  cin >> n;
  if (!n) return false;
  cin >> m;
  rep(i, 1, n) rep(j, 1, m) cin >> a[i][j];
  rep(j, 1, m) a[0][j] = '*';
  rep(i, 1, n) a[i][0] = '*';

  num = 0;
  across.clear();
  down.clear();
  rep(i, 1, n) rep(j, 1, m) {
    id[i][j] = 0;
    if (a[i][j] == '*') continue;
    if (a[i - 1][j] == '*' || a[i][j - 1] == '*') {
      id[i][j] = ++num;
    }
    if (a[i - 1][j] == '*') {
      string w;
      int r = i;
      rep(r, i, n) {
        if (a[r][j] == '*') break;
        w.push_back(a[r][j]);
      }
      down.push_back(Node{num, w});
    }
    if (a[i][j - 1] == '*') {
      string w;
      int c = j;
      rep(c, j, m) {
        if (a[i][c] == '*') break;
        w.push_back(a[i][c]);
      }
      across.push_back(Node{num, w});
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int i = 0;
  while (true) {
    if (!solve()) break;
    ++i;
    if (i > 1) cout << endl;
    cout << "puzzle #" << i << ":\n";
    cout << "Across\n";
    for (Node x : across) {
      cout << setw(3) << x.id;
      cout << '.' << x.word << endl;
    }
    cout << "Down\n";
    for (Node x : down) {
      cout << setw(3) << x.id;
      cout << '.' << x.word << endl;
    }
  }
  return 0;
}